﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZSZ.Service.Entity;

namespace ZSZ.Service
{
    class CommonService<T> where T:BaseEntity
    {
        private ZSZDBcontext ZSZDBcontext { get; set; }
        public CommonService(ZSZDBcontext z) {
            this.ZSZDBcontext = z;
        }
        public IQueryable<T> GetAll() {
            return ZSZDBcontext.Set<T>().Where(i=>i.IsDeleted==false);
        }
        public void MarkDeleted(long id) {
            var data = GetAll().SingleOrDefault(d => d.Id == id);
            data.IsDeleted = true;
            ZSZDBcontext.SaveChanges();
        }
        public T GetById(long id) {
            return GetAll().SingleOrDefault(d=>d.Id==id);
        }
    }
}
